package com.base.third.mob

import com.base.config.BaseConfig
import com.yfree.utils.YMD5Utils
import org.springframework.stereotype.Service
import java.util.*

@Service
class MobService(
        val mobClient: MobClient,
) {
    //验证码登录
    fun verify(
            phone: String,
            code: String,
            appkey: String = BaseConfig.mob_AppKey,
            zone: String = "86",
    ): Boolean {
        val result = mobClient.verify(phone, code, appkey, zone)
        return result != null && result["status"] == 200
    }

    //免验证码登录
    fun sdkClientFreeLogin(
            opToken: String,
            operator: String,
            token: String,
            appkey: String = BaseConfig.mob_AppKey,
            timestamp: Long = Date().time,
            sign: String = YMD5Utils.getMD5("appkey=$appkey&opToken=$opToken&operator=$operator&timestamp=$timestamp&token=$token${BaseConfig.mob_AppSecret}"),
    ): String? {
        val result = mobClient.sdkClientFreeLogin(opToken, operator, token, appkey, timestamp, sign)
        if (result == null || result["status"] != 200) return null
        return result["res"]?.toString()
    }
}